-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Process::Status Windows-compatible #9021
Conversation
Skip the bitmasks/signal handling. Co-Authored-By: Stephanie Hobbs <steph@rx14.co.uk>
It's not an alternative, more like a subset. Deprecating that method is just that, an added annotation. It does not remove any need for that special handling. |
Yeah, you're right. Let me rephrase: It would have been better to deprecate and remove |
Hm no, it really makes no difference. The two PRs support each other well (i.e. merging either one makes the other one make even more sense) but don't depend on each other in any way at all (other than needing a manual merge) |
BTW there's no backwards-incompatible change here |
Adding more |
I can agree with that only on the matter of principle. But I definitely think for this particular case keeping it in one file is better for maintenance. |
@RX14 As per #8647 (comment) I'd remove those platform-specifics from |
Me too. Just, |
I can grant this wish by copying the implementations of reader methods to the place where the struct is constructed, without having any idea how this exit status is processed. |
The problem is that the method returns |
Or just don't have |
Yes I'm very tempted to implement it as such... The discussion is sadly spread so much, I'll add by comparing Crystal to what Python does. For my own understanding, too. The outcome is that Python just returns a negative number if it's a signal. $ crystal eval 'require "process"; r = Process.run("cat", input: :inherit); p! r.exit_status, r.exit_code, r.exit_signal' & while ! killall cat; do sleep 0.5; done; fg
r.exit_status # => 15
r.exit_code # => 0
r.exit_signal # => TERM $ python3 -c 'import subprocess; print(subprocess.call("cat"))' & while ! killall cat; do sleep 0.5; done; fg
-15 $ crystal eval 'require "process"; r=Process.run("false", input: :inherit); p! r.exit_status, r.exit_code, r.exit_signal'
r.exit_status # => 256
r.exit_code # => 1
r.exit_signal # => Unhandled exception: Unknown enum Signal value: 0 (Exception) $ python3 -c 'import subprocess; print(subprocess.call("false"))'
1 It also seems quite strange to me that Crystal enforces that you can't find out the signal if it's one that Crystal is not aware of. Also returning |
And coming back to the "dumb struct", it could turn out quite inefficient in terms of storage, perhaps as far as this: |
Honestly I'm not so interested in solving the design issue right here. I think that the current state of the pull request is the only way to do it without hitting any of the disadvantages that other approaches here are prone to:
If one wants to follow this up with a more idealistic approach, this doesn't make it harder to do. |
Please read this, I summarized all possible status codes: Having looked into how diverse the exit status can be, I don't see it as reasonable to pre-process and store this data in a plain struct that is the same on all platforms. |
This is better than ArithmeticOverflow, and actually this is what CMD shell does anyway. ```cmd > py -c "import sys; sys.exit(-5)" > echo %ERRORLEVEL% -5 ```
I am asking to merge this as is. There are no changes in behavior on supported systems. The only complaints are about where the code should ideally be. But it's clear that this will need more thought, and we will be in a better position for maneuvers after Process support on Windows is landed (as it will actually make the file crystal/system/process exist, which is where you want me to put this). But that change is blocked on this one. cc @asterite |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to have the discussion about how to refactor this forgotten, but this is fine for now.
Thanks @oprypin |
#9064 will be my only followup to this. It's the only way to meet the above requirements. The suggestions for refactoring here insisted on storing/exposing only processed data and throwing out |
Skip the bitmasks/signal handling.
Closes #8537